package com.leador.http;


import com.leador.module.response.Result;
import com.leador.module.response.entity.Columns;
import com.leador.module.response.entity.CustomField;
import com.leador.module.response.entity.Entities;
import com.leador.module.response.entity.EntityCloumnResult;
import com.leador.module.response.entity.EntityResult;
import com.leador.module.response.entity.Location;
import com.leador.module.response.entity.RealtimePoint;
import com.leador.module.response.entity.TrackColumns;
import com.leador.module.response.fence.AlarmResult;
import com.leador.module.response.fence.Alarms;
import com.leador.module.response.fence.HisAlarmResult;
import com.leador.module.response.fence.Center;
import com.leador.module.response.fence.FenceResult;
import com.leador.module.response.fence.Fences;
import com.leador.module.response.fence.MonitoredPerson;
import com.leador.module.response.fence.MonitoredPersonAlarms;
import com.leador.module.response.fence.Valid_times;
import com.leador.module.response.track.Points;
import com.leador.module.response.track.TrackCloumnResult;
import com.leador.module.response.track.TrackResult;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by lhy on 2016/9/2.
 */
public class ResultParse {
    //addcolumn  deletecolumn add update delete
    public static Result resultParse(String json){
        Result result = new Result();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {

        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            result.setMessage(message);
        } catch (Exception e) {
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            result.setStatus(status);
        } catch (Exception e) {
        }
        return result;
    }

    public static TrackCloumnResult trackCloumnListParse(String json){
        TrackCloumnResult trackCloumResult = new TrackCloumnResult();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            trackCloumResult.setMessage(message);
        } catch (Exception e) {
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            trackCloumResult.setStatus(status);
        } catch (Exception e) {
        }
        if(jsonObject != null){
            JSONArray jsonArray = null;
            try {
                jsonArray = jsonObject.getJSONArray("columns");
            } catch (JSONException e) {
            }

            List<Columns> columnsList = new ArrayList<Columns>();
            if(jsonArray != null){
                for(int i=0;i<jsonArray.length();i++){
                    Columns columns = new Columns();
                    JSONObject jsonObject1 = null;
                    try {
                        jsonObject1 = jsonArray.getJSONObject(i);
                    } catch (JSONException e) {
                    }

                    if(jsonObject1 != null){
                        String service_id = null;
                        try {
                            service_id = jsonObject1.getString("service_id");
                            columns.setService_id(service_id);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String create_time = null;
                        try {
                            create_time = jsonObject1.getString("create_time");
                            columns.setCreate_time(create_time);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String modify_time = null;
                        try {
                            modify_time = jsonObject1.getString("modify_time");
                            columns.setModify_time(modify_time);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String column_key = null;
                        try {
                            column_key = jsonObject1.getString("column_key");
                            columns.setColumn_key(column_key);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String column_desc = null;
                        try {
                            column_desc = jsonObject1.getString("column_desc");
                            columns.setColumn_desc(column_desc);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String column_type = null;
                        try {
                            column_type = jsonObject1.getString("column_type");
                            columns.setColumn_type(column_type);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    columnsList.add(columns);
                }
                trackCloumResult.setColumns(columnsList);
            }
        }
        return trackCloumResult;
    }

    public static EntityCloumnResult entityCloumnListParse(String json){
        EntityCloumnResult trackCloumResult = new EntityCloumnResult();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            trackCloumResult.setMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            trackCloumResult.setStatus(status);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(jsonObject != null){
            JSONArray jsonArray = null;
            try {
                jsonArray = jsonObject.getJSONArray("columns");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            List<Columns> columnsList = new ArrayList<Columns>();
            if(jsonArray != null){
                for(int i=0;i<jsonArray.length();i++){
                    Columns columns = new Columns();
                    JSONObject jsonObject1 = null;
                    try {
                        jsonObject1 = jsonArray.getJSONObject(i);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    if(jsonObject1 != null){
                        String service_id = null;
                        try {
                             service_id = jsonObject1.getString("service_id");
                            columns.setService_id(service_id);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String create_time = null;
                        try {
                            create_time = jsonObject1.getString("create_time");
                            columns.setCreate_time(create_time);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String modify_time = null;
                        try {
                            modify_time = jsonObject1.getString("modify_time");
                            columns.setModify_time(modify_time);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String column_key = null;
                        try {
                            column_key = jsonObject1.getString("column_key");
                            columns.setColumn_key(column_key);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String column_desc = null;
                        try {
                            column_desc = jsonObject1.getString("column_desc");
                            columns.setColumn_desc(column_desc);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        String column_type = null;
                        try {
                            column_type = jsonObject1.getString("column_type");
                            columns.setColumn_type(column_type);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    columnsList.add(columns);
                }
                trackCloumResult.setColumns(columnsList);
            }
        }
        return trackCloumResult;
    }

    public static EntityResult entityListParse(String json){
        EntityResult entityResult = new EntityResult();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            entityResult.setMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            entityResult.setStatus(status);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String total = null;
        try {
            total = jsonObject != null ? jsonObject.getString("total") : null;
            entityResult.setTotal(Integer.parseInt(total));
        } catch (Exception e) {
            e.printStackTrace();
        }

        JSONArray jsonArray = null;
        try {
            assert jsonObject != null;
            jsonArray = jsonObject.getJSONArray("entities");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if(jsonArray != null){
            List<Entities> entitiesList  =new ArrayList<Entities>();
            for(int i=0;i<jsonArray.length();i++){
                Entities entities = new Entities();
                JSONObject jsonObject1 = null;
                try {
                    jsonObject1 = jsonArray.getJSONObject(i);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                if(jsonObject1 != null){

                    String create_time = null;
                    try {
                        create_time = jsonObject1.getString("create_time");
                        entities.setCreate_time(create_time);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    String modify_time = null;
                    try {
                        modify_time = jsonObject1.getString("modify_time");
                        entities.setModify_time(modify_time);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    String entity_name = null;
                    try {
                        entity_name = jsonObject1.getString("entity_name");
                        entities.setEntity_name(entity_name);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    RealtimePoint realtimePoint = new RealtimePoint();
                    JSONObject jsonObject2 = null;
                    try {
                        jsonObject2  = jsonObject1.getJSONObject("realtime_point");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    if(jsonObject2 != null){

                        String loc_time = null;
                        try {
                            loc_time = jsonObject2.getString("loc_time");
                            realtimePoint.setLoc_time(Integer.parseInt(loc_time));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        String speed = null;
                        try {
                            speed = jsonObject2.getString("speed");
                            realtimePoint.setSpeed(Double.parseDouble(speed));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        String direction = null;
                        try {
                            direction = jsonObject2.getString("direction");
                            realtimePoint.setDirection(Integer.parseInt(direction));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        List<Location> locationList = new ArrayList<Location>();
                        Location location = new Location();
                        JSONArray jsonArray1 = null;
                        try {
                            jsonArray1 = jsonObject2.getJSONArray("location");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        if(jsonArray1!=null){
//                            for(int k=0;k<jsonArray1.length();k++){
                                String locationJson = null;
                                try {
                                    Double longitude = jsonArray1.getDouble(0);
                                    Double latitude = jsonArray1.getDouble(1);
                                    location.setLongitude(longitude);
                                    location.setLatitude(latitude);
                                    locationList.add(location);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
//                            }
                            realtimePoint.setLocation(locationList);
                        }


                        TrackColumns trackColumns = new TrackColumns();
                        Map<String,String> stringStringMap = new HashMap<String,String>();
                        JSONObject jsonObject3 = null;
                        try {
                            jsonObject3 = jsonObject2.getJSONObject("trackColumns");
                            Iterator<String> set = jsonObject3.keys();
                            while(set.hasNext()) {
                                String key = set.next();
                                String value = jsonObject3.getString(key);
                                stringStringMap.put(key,value);
                            }
                            trackColumns.setStringStringMap(stringStringMap);
                            realtimePoint.setTrackColumns(trackColumns);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        entities.setRealtime_point(realtimePoint);
                    }
                }
                entitiesList.add(entities);
            }
            entityResult.setEntities(entitiesList);
        }
            return entityResult;
    }

    public static FenceResult fenceListParse(String json){
        FenceResult fenceResult = new FenceResult();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            fenceResult.setMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            fenceResult.setStatus(status);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String size = null;
        try {
            size = jsonObject != null ? jsonObject.getString("size") : null;
            fenceResult.setSize(Integer.valueOf(size));
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<Fences> fencesList = new ArrayList<Fences>();
        JSONArray jsonArray = null;
        try {
            jsonArray = jsonObject.getJSONArray("fences");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //fences
        if(jsonArray != null && jsonArray.length() > 0){
            for(int n =0;n<jsonArray.length();n++){
                Fences fences = new Fences();
                JSONObject fencesJob = null;
                try {
                     fencesJob = jsonArray.getJSONObject(n);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                String createTime = null;
                try {
                    createTime = fencesJob != null ? fencesJob.getString("create_time") : null;
                    fences.setCreate_time(createTime);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String modifyTime = null;
                try {
                    modifyTime = fencesJob != null ? fencesJob.getString("modify_time") : null;
                    fences.setModify_time(modifyTime);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String fence_id = null;
                try {
                    fence_id = fencesJob != null ? fencesJob.getString("fence_id") : null;
                    fences.setFence_id(fence_id);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String name = null;
                try {
                    name = fencesJob != null ? fencesJob.getString("name") : null;
                    fences.setName(name);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String desc = null;
                try {
                    desc = fencesJob != null ? fencesJob.getString("desc") : null;
                    fences.setDesc(desc);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String creator = null;
                try {
                    creator = fencesJob != null ? fencesJob.getString("desc") : null;
                    fences.setCreator(creator);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String valid_cycle = null;
                try {
                    valid_cycle = fencesJob != null ? fencesJob.getString("valid_cycle") : null;
                    fences.setValid_cycle(Integer.parseInt(valid_cycle));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String coord_type = null;
                try {
                    coord_type = fencesJob != null ? fencesJob.getString("coord_type") : null;
                    fences.setCoord_type(Integer.parseInt(coord_type));
                } catch (Exception e) {
                }

                String shape = null;
                try {
                    shape = fencesJob != null ? fencesJob.getString("coordStr") : null;
                    fences.setShape(Integer.valueOf(shape));
                } catch (Exception e) {
                }

                String coordStr = null;
                try {
                    coordStr = fencesJob != null ? fencesJob.getString("coordStr") : null;
                    fences.setCoordStr(coordStr);
                } catch (Exception e) {
                }

                String radius = null;
                try {
                    radius = fencesJob != null ? fencesJob.getString("radius") : null;
                    fences.setRadius(Integer.valueOf(radius));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String alarm_condition = null;
                try {
                    alarm_condition = fencesJob != null ? fencesJob.getString("alarm_condition") : null;
                    fences.setAlarm_condition(Integer.parseInt(alarm_condition));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                List<String> monitoredPersonsList = new ArrayList<String>();
                String monitored_persons = null;
                try {
                    monitored_persons = fencesJob != null ? fencesJob.getString("monitored_persons") : null;
                    String[] monitored_personsStrings = jsonToStrings(monitored_persons);
                    if(monitored_personsStrings.length>0){
                        for(int i=0;i<monitored_personsStrings.length;i++){
                            monitoredPersonsList.add(monitored_personsStrings[i]);
                        }
                    }
                    fences.setMonitored_persons(monitoredPersonsList);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                JSONArray validArr = null;
                List<Valid_times> valid_timesList = new ArrayList<Valid_times>();
                try {
                    validArr = fencesJob != null ? fencesJob.getJSONArray("valid_times") : null;
                    if(validArr != null && validArr.length() >0){
                        for(int k=0;k<validArr.length();k++){
                            JSONObject validJbt = validArr.getJSONObject(k);
                            Valid_times valid_times =new Valid_times();
                            String start = validJbt.getString("start");
                            String end = validJbt.getString("end");
                            valid_times.setStart(Integer.parseInt(start));
                            valid_times.setEnd(Integer.parseInt(end));
                            valid_timesList.add(valid_times);
                        }
                    }
                    fences.setValid_times(valid_timesList);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                JSONObject centJOt = null;
                try {
                    centJOt = fencesJob.getJSONObject("center");
                        Center center = new Center();
                        String longitude = centJOt.getString("longitude");
                        String latitude = centJOt.getString("latitude");
                        center.setLatitude(Double.parseDouble(latitude));
                        center.setLongitude(Double.parseDouble(longitude));
                    fences.setCenter(center);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                fencesList.add(fences);
            }
        }
        fenceResult.setFences(fencesList);
        return fenceResult;
    }

    public static AlarmResult alarmParse(String json){
        AlarmResult alarmResult = new AlarmResult();

        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            alarmResult.setMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            alarmResult.setStatus(status);
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONArray jsonArray = null;
        try {
            assert jsonObject != null;
            jsonArray = jsonObject.getJSONArray("monitored_person_statuses");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if(jsonArray != null){
            List<MonitoredPerson> monitoredPersonsList = new ArrayList<MonitoredPerson>();
            for(int i=0;i<jsonArray.length();i++){
                MonitoredPerson monitoredPerson = new MonitoredPerson();
                JSONObject jsonObject1 = null;
                try {
                     jsonObject1 = jsonArray.getJSONObject(i);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                String monitored_Person = null;
                try {
                     monitored_Person = jsonObject1 != null ? jsonObject1.getString("monitored_person") : null;
                    monitoredPerson.setMonitored_person(monitored_Person);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                String monitored_status = null;
                try {
                    monitored_status = jsonObject1 != null ? jsonObject1.getString("monitored_status") : null;
                    monitoredPerson.setMonitored_status(Integer.parseInt(monitored_status));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                monitoredPersonsList.add(monitoredPerson);
            }
            alarmResult.setMonitored_person_statuses(monitoredPersonsList);
        }
        return alarmResult;
    }


    public static HisAlarmResult alarmssResult(String json){
        HisAlarmResult alarmsResult = new HisAlarmResult();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String message = null;
        try {
            message = jsonObject != null ? jsonObject.getString("message") : null;
            alarmsResult.setMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String status = null;
        try {
            status = jsonObject != null ? jsonObject.getString("status") : null;
            alarmsResult.setStatus(status);
        } catch (Exception e) {
            e.printStackTrace();
        }



        JSONArray jsonArray = null;
        try {
            assert jsonObject != null;
            jsonArray = jsonObject.getJSONArray("monitored_person_alarms");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if(jsonArray != null){
            List<MonitoredPersonAlarms> monitored_person_alarmses = new ArrayList<MonitoredPersonAlarms>();
            for(int i=0;i<jsonArray.length();i++){
                MonitoredPersonAlarms monitored_person_alarms = new MonitoredPersonAlarms();

                JSONObject jsonObject1 = null;
                try {
                    jsonObject1 = jsonArray.getJSONObject(i);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                String monitored_person = null;
                try {
                    monitored_person = jsonObject1 != null ? jsonObject1.getString("monitored_person") : null;
                    monitored_person_alarms.setMonitored_person(monitored_person);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                String alarm_size = null;
                try {
                    alarm_size = jsonObject1 != null ? jsonObject1.getString("alarm_size") : null;
                    monitored_person_alarms.setAlarm_size(Integer.parseInt(alarm_size));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                JSONArray jsonArray1 = null;
                try {
                    assert jsonObject1 != null;
                    jsonArray1 = jsonObject1.getJSONArray("alarms");
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                if(jsonArray1!=null){
                    List<Alarms> alarmsList = new ArrayList<Alarms>();
                    for(int n=0;n<jsonArray1.length();n++){
                        Alarms alarms = new Alarms();

                        JSONObject jsonObject2 = null;
                        try {
                            jsonObject2 = jsonArray1.getJSONObject(n);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        long time;
                        try {
                            time = jsonObject2 != null ? jsonObject2.getLong("time") : 0;
                            alarms.setTime(time);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        int action;
                        try {
                            action = jsonObject2 != null ? jsonObject2.getInt("action") : 0;
                            alarms.setAction(action);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        alarmsList.add(alarms);
                    }
                    monitored_person_alarms.setAlarms(alarmsList);
                }
                monitored_person_alarmses.add(monitored_person_alarms);
            }
            alarmsResult.setMonitored_person_alarms(monitored_person_alarmses);
        }
        return alarmsResult;
    }

    public static TrackResult trackParse(String json){
        TrackResult trackResult = new TrackResult();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
        } catch (JSONException e) {
            e.printStackTrace();
            return trackResult;
        }

        String message = null;
        try {
            message = jsonObject.getString("message") ;
            trackResult.setMessage(message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String status = null;
        try {
            status =  jsonObject.getString("status");
            trackResult.setStatus(status);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String total = null;
        try {
            total =  jsonObject.getString("total");
            trackResult.setTotal(Integer.parseInt(total));
        } catch (Exception e) {
            e.printStackTrace();
        }

        String distance = null;
        try {
            distance =  jsonObject.getString("distance");
            trackResult.setDistance(Double.parseDouble(distance));
        } catch (Exception e) {
            e.printStackTrace();
        }

        String entityName = null;
        try {
            entityName = jsonObject.getString("entity_name") ;
            trackResult.setEntity_name(entityName);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String size = null;
        try {
            size =  jsonObject.getString("size");
            trackResult.setSize(Integer.parseInt(size));
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONArray jsonArray = null;
        try {
            jsonArray = jsonObject.getJSONArray("points");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        List<Points> pointses = new ArrayList<Points>();
        if(jsonArray != null){
            for(int n=0;n<jsonArray.length();n++){
                Points points =  new Points();
                JSONObject jsonObject1 = null;
                try {
                     jsonObject1 = jsonArray.getJSONObject(n);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                String create_time = null;
                try {
                    assert jsonObject1 != null;
                    create_time =  jsonObject1.getString("create_time");
                    points.setCreate_time(create_time);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String entity_name = null;
                try {
                    entity_name =  jsonObject1.getString("entity_name");
                    points.setEntity_name(entity_name);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String longitude = null;
                try {
                    longitude =  jsonObject1.getString("longitude");
                    points.setLongitude(Double.parseDouble(longitude));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String latitude = null;
                try {
                    latitude =  jsonObject1.getString("latitude");
                    points.setLatitude(Double.parseDouble(latitude));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String loc_time = null;
                try {
                    loc_time =  jsonObject1.getString("loc_time");
                    points.setLoc_time(Integer.parseInt(loc_time));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String speed = null;
                try {
                    speed =  jsonObject1.getString("speed");
                    points.setSpeed(Double.parseDouble(speed));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                CustomField customField = new CustomField();
                Map<String,String> stringStringMap = new HashMap<String,String>();
                JSONObject jsonObject2 = null;
                try {
                    jsonObject2 = jsonObject1.getJSONObject("custom_field");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                Iterator<String> iterator = jsonObject2.keys();
                while (iterator.hasNext()){
                    String key = iterator.next();
                    try {
                        String value = jsonObject2.getString(key);
                        stringStringMap.put(key,value);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                customField.setCustomFiledMap(stringStringMap);
                points.setCustom_field(customField);
                pointses.add(points);
            }
            trackResult.setPoints(pointses);
        }
        return trackResult;
    }

    public static String[] jsonToStrings(String str){
        String[] strings = new String[0];
        if(str == null || str.length() > 0){
            String str1 = str.substring(1,str.length()-1);
            strings = str1.split(",");
        }
        return strings;
    }
}
